package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.port.fee.entity.Cargo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 货物Mapper接口
 */
@Mapper
public interface CargoMapper extends BaseMapper<Cargo> {
    
    /**
     * 按月统计货物流量
     * @param year 年份
     * @return 月度统计数据
     */
    @Select("SELECT MONTH(entry_time) as month, " +
            "COUNT(*) as inCount, " +
            "SUM(CASE WHEN exit_time IS NOT NULL THEN 1 ELSE 0 END) as outCount " +
            "FROM cargo " +
            "WHERE YEAR(entry_time) = #{year} " +
            "GROUP BY MONTH(entry_time)")
    List<Map<String, Object>> countCargoFlowByMonth(@Param("year") Integer year);
    
    /**
     * 按货物类型统计数量
     * @return 类型统计数据
     */
    @Select("SELECT cargo_type as type, COUNT(*) as count " +
            "FROM cargo " +
            "GROUP BY cargo_type")
    List<Map<String, Object>> countCargoByType();
    
    /**
     * 按状态统计货物数量
     * @param status 状态值
     * @return 统计结果
     */
    @Select("SELECT COUNT(*) as count FROM cargo WHERE status = #{status}")
    Map<String, Object> countCargoByStatus(@Param("status") Integer status);
} 